﻿using Equipment.Errorcode;
using Equipment.Errorcode.ErrorCode;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Equipment.Errorcode
{
    public class ApiResult
    {

        /// <summary>
        /// 是否成功
        /// </summary>
        public bool IsSuc { get; private set; }

        /// <summary>
        /// 接口请求结果的状态码
        /// </summary>
        public StatusCodeEnum Code { get; private set; }

        /// <summary>
        /// 返回的信息
        /// </summary>
        public string Msg { get; private set; }
        /// <summary>
        /// 返回数据
        /// </summary>
        public object? Data { get; set; } // 返回的数据



        // 成功响应
        public static ApiResult Ok(object? data, string message)
        {
            return new ApiResult
            {
                IsSuc = true,
                Msg = message,
                Data = data,
                Code = StatusCodeEnum.Success
            };
        }

        // 失败响应
        public static ApiResult Fail(string message)
        {
            return new ApiResult
            {
                IsSuc = false,
                Msg = message,
                Data = default,
                Code = StatusCodeEnum.NotFound
            };
        }
    }
}







